package com.bdsy.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bdsy.common.utils.UUIDUtil;
import com.bdsy.system.dao.RoleAuthMapper;
import com.bdsy.system.model.RoleAuth;
import com.bdsy.system.service.RoleAuthService;

/**
 * ClassName:UserServiceImpl
 * Description: TODO 添加描述.
 * @author   Administrator
 * @version  
 * @since    JDK 1.8
 */

@Service("roleAuthService")
public class RoleAuthServiceImpl implements RoleAuthService{

    @Autowired
    RoleAuthMapper roleAuthMapper;
    
	@Override
	public int getRoleAuthCount(String roleId) {
		int role = roleAuthMapper.selectRoleAuthCount(roleId);
		return role;
	}
	
	@Override
	public int deleteRoleAuth(String roleId) {
		int role = roleAuthMapper.deleteRoleAuth(roleId);
		return role;
	}
	
	@Override
	public int addRoleAuth(String roleId,String authId) {
		int result = 0;
		RoleAuth roleAuth = new RoleAuth();
		try 
		{
			String[] str = null;   
	        str = authId.split(",");
			if(!"0".equals(roleId))
			{
				for(String id:str)
				{
					roleAuth.setAuthId(id);
					roleAuth.setRoleId(roleId);
					roleAuth.setRoleAuthId(UUIDUtil.randomUUID());
					result = roleAuthMapper.insertRoleAuth(roleAuth);
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return result;
	}
    
}

